<template>
    <scroll-view 
        :scroll-y="true"
        class="jyd_cp">
        <view class="container">
            <u-table>
                <u-tr>
                    <u-th>挂号单</u-th>
                    <u-th>姓名</u-th>
                    <u-th>性别</u-th>
                    <u-th>科室</u-th>
                </u-tr>
                <u-tr 
                    v-for="(item,index) in dataList" 
                    :key="index"
                    @click.native="findDetail(item)">
                    <u-td>{{item.rid}}</u-td>
                    <u-td>{{item.name}}</u-td>
                    <u-td>{{item.sex}}</u-td>
                    <u-td>{{item.sectionRoom}}</u-td>
                </u-tr>
            </u-table>
            <view class="bt_list">
                <u-button 
                    type="success"
                    :loading="loading"
                    @click="getData">
                    刷新
                </u-button>
            </view>
            <u-toast ref="uToast" />
        </view>
    </scroll-view>
</template>

<script>
//检药单组件
import SelectOfficeInputCp from "@/components/public/SelectOfficeInput";
import {getNoPayUsers} from "@/common/api"
export default {
    components:{
        SelectOfficeInputCp,
    },
    props:{
        show:{  //当前页是否显示
            type:Boolean,
            default:false,
        },
        pageShow:{  //当前页面是否显示
            type:Boolean,
            default:false,
        },
    },
    data() {
        return {
            loading:false,  //查询加载状态
            findData:"", //根据挂号单查询挂单病人
            dataList:[],  //数据列表
        }
    },
    watch:{
        show:{
            handler(newValue){
                //当该页可见并且数据为空时获取数据
                if(newValue && this.dataList.length==0) this.getData();
            },
            immediate:true,
        },
        pageShow:{
            handler(newValue){
                //当该页可见并且页面级可见时
                if(newValue && this.show) this.getData();
            },
            immediate:true,
        },
    },
    methods: {
        findDetail(item){
            uni.navigateTo({
                url: '/pages/yf_manage/views/details?rid='+item.rid+
                "&name="+item.name,
            });
        },
        getData(){  //获取数据
            if(this.loading) return;  //如果正在加载则返回
            this.loading = true;
            getNoPayUsers(
                {
                    status:1,
                },
            ).then(data=>{
                this.dataList = data;
            }).finally(()=>{
                this.loading = false;
            }).catch(msg=>{
                this.$refs.uToast.show({
                    title: msg,
                    position:'top',
                    type: 'error',
                });
            });
        },
    },
}
</script>
<style scoped lang="scss">
    .jyd_cp{
        height: calc(100vh - 90rpx);
        .container{
            padding: 35rpx;
            box-sizing: border-box;
            .bt_list{
                margin-top: 35rpx;
            }
        }
    }
</style>
